<?php
namespace Amis\dataviewer;

use Amis\Basics\AmisBasics;

class Images extends AmisBasics
{
    /**
     * 如果在 Table、Card 和 List 中，为"image"；在 Form 中用作静态展示，为"static-images"
     */
    public string $type        = 'images';
    public string $type_static = 'static-images';

    public function className(string $className)
    {
        $this->className = $className;
        return $this;
    }

    /**
     * 默认展示图片
     * @param string $defaultImage
     * @return $this
     */
    public function defaultImage(string $defaultImage)
    {
        $this->defaultImage = $defaultImage;
        return $this;
    }

    /**
     * 图片数组
     * @param string|array $value
     * @return $this
     */
    public function value($value)
    {
        $this->value = $value;
        return $this;
    }

    /**
     * 数据源
     * @param string $source
     * @return $this
     */
    public function source(string $source)
    {
        $this->source = $source;
        return $this;
    }

    /**
     * 分隔符，当 value 为字符串时，用该值进行分隔拆分
     * @param string $delimiter
     * @return $this
     */
    public function delimiter(string $delimiter)
    {
        $this->delimiter = $delimiter;
        return $this;
    }

    /**
     * 预览图地址，支持数据映射获取对象中图片变量
     * @param string $src
     * @return $this
     */
    public function src(string $src)
    {
        $this->src = $src;
        return $this;
    }

    /**
     * 原图地址，支持数据映射获取对象中图片变量
     * @param string $originalSrc
     * @return $this
     */
    public function originalSrc(string $originalSrc)
    {
        $this->originalSrc = $originalSrc;
        return $this;
    }

    /**
     * 支持放大预览
     * @param bool $enlargeAble
     * @return $this
     */
    public function enlargeAble(bool $enlargeAble)
    {
        $this->enlargeAble = $enlargeAble;
        return $this;
    }

    /**
     * 预览图比例，可选：'1:1', '4:3', '16:9'
     * @param string $thumbRatio
     * @return $this
     */
    public function thumbRatio(string $thumbRatio = '1:1')
    {
        if (in_array($thumbRatio, ['1:1', '4:3', '16:9'])) {
            $this->thumbRatio = $thumbRatio;
        }
        return $this;
    }

    /**
     * 预览图模式，可选：'w-full', 'h-full', 'contain', 'cover'
     * @param string $thumbMode
     * @return $this
     */
    public function thumbMode(string $thumbMode = 'contain')
    {
        if (in_array($thumbMode, ['w-full', 'h-full', 'contain', 'cover'])) {
            $this->thumbMode = $thumbMode;
        }
        return $this;
    }
}
